home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 27 / MacFormat n. 27 (Spain) / Mac Format 26.bin / Shareware / Comunicaciones / mtx2html 1.5.5 / mtx2html.pl < prev    next >
Encoding:
Perl Script  |  1997-01-20  |  27.6 KB  |  876 lines

  1. #!perl
  2.  
  3. #  mtx2html.pl
  4. #  MTX to HTML Converter
  5. #  Version 1.5.5 (1/18/97)
  6. #  Richard Rathe <rrathe@dean.med.ufl.edu>
  7. #  http://www.med.ufl.edu/medinfo/mtx/
  8. #  Copyright 1996 by Richard Rathe
  9.  
  10. #  Revision History:
  11. #   8/1/96  - 1.5   - initial release
  12. #   9/1/96  - 1.5.1 - fixed minor DTD problems
  13. #   9/15/96 - 1.5.2 - fixed parent quiz page links
  14. #   10/1/96 - 1.5.3 - minor changes and fixes
  15. #   1/1/97  - 1.5.4 - added embedded movies, big, small, super, sub, and non print
  16. #   1/18/97 - 1.5.5 - added hidden movies (audio only), about and keyword meta info
  17.  
  18. $mtxinfo = "<!-- This file was created using mtx2html.pl v1.5.5 by Richard Rathe. -->";
  19. $dtdinfo = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">";
  20. $movinfo = "WIDTH=250 HEIGHT=204 AUTOPLAY=\"true\" PLUGINSPAGE=\"http://quicktime.apple.com\"";
  21.  
  22. @letters = ('#','A','B','C','D','E','F','G','H','I','J','K',
  23. 'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  24.  
  25. ### process file(s)
  26.  
  27. print "Starting MTX2HTML v1.5.5...\n";
  28.  
  29. while(@ARGV > 0)               # drag and drop file(s) on Mac droplet
  30. {                              # or from command line under MSDOS, UNIX
  31.   $infile = shift(@ARGV);
  32.   $outfile = $infile;
  33.   $outfile =~ s/(.*\.)(.*)/$1html/;
  34.   if($infile =~ /.*\.mtx/i) {&mtx2html($infile,$outfile);}
  35.   else { print "   skip: $infile\n"; }
  36. }
  37.  
  38. print "\n";
  39.  
  40. ### main program ###
  41.  
  42. sub mtx2html                     # requires two args:
  43. {                                #   path:infile
  44.   @toc = ();                     #   path:outfile
  45.   %info = ();
  46.   $main = "";
  47.   $head = "";
  48.   $tail = "";
  49.   $navi = "";
  50.   $tocf = "";
  51.   $akey = "";
  52.   $qtxt = "";
  53.   $stxt = "";
  54.   $para = "";
  55.   $path = "";
  56.   $hcount = 0;
  57.   $lcount = 0;
  58.   $tcount = 0;
  59.   $pcount = 0;
  60.   $qcount = 0;
  61.   $acount = 0;
  62.  
  63.   $_[1] =~ /(.*:)(.*)\.html/; $qpath = $1; $qfile = $2;
  64.  
  65.   open(INFILE,$_[0]) || die "Can't open input file $_[0].\n";
  66.   print "reading: $_[0]\n";
  67.  
  68.   ### parse file one line at a time
  69.  
  70.   while (<INFILE>) {
  71.     /.*\n/ && chop;                      # last line may not have a \n
  72.  
  73.     s/&/&/g;                         # fix special chars
  74.     s/</</g;
  75.     s/>/>/g;
  76.     s/\"/"/g;
  77.  
  78.     if($_ eq "")                         # blank line
  79.     {
  80.       &flush_quest;
  81.       &flush_para;
  82.       &flush_pref;
  83.       #&flush_list;    # allow blank lines in lists
  84.       #&flush_table;   # allow blank lines in tables
  85.     }
  86.     elsif (/^%%.*/)                      # comment (%%)
  87.     {
  88.        # do nothing
  89.     }
  90.     elsif (/^%(\S+)\s*(.*)/)             # page info (%)
  91.     {
  92.       $key = $1;
  93.       $key =~ tr/a-z/A-Z/;
  94.       $info{$key} = $2;
  95.       if ($key eq "IMAGES") { $path = $2; }
  96.     }
  97.     elsif (/(^#+)(.*)/)                  # heading (#)
  98.     {
  99.       &flush_quest;
  100.       &flush_para;
  101.       &flush_list;
  102.       &flush_table;
  103.       &flush_pref;
  104.       $x = length($1) + 1;
  105.       $htext = $2;
  106.  
  107.       if ($htext =~ /^\$(.*)/) { $htext = $1; $align = " ALIGN=center"; }
  108.       else { $align = ""; }
  109.  
  110.       if ($htext =~ /(.*)#=(\S*)/) { $htext = $1; $h1 = "<A NAME=\"$2\">"; $h2 = "<\/A>"; }
  111.       else { $h1 = ""; $h2 = ""; }
  112.  
  113.       if ($htext =~ /^!(.*)/)
  114.       {
  115.         $info{'HEADING'} = $1;
  116.                                 $main .= "\n!HEAD!\n\n";
  117.       }
  118.       elsif ($htext =~ /(.*)#(\S*)/)
  119.       {
  120.         $hcount++;
  121.         $toc[$hcount-1] .= "$x|<A HREF=\"$2\">$1<\/A>";
  122.       }
  123.       else
  124.       {
  125.         $hcount++;
  126.         if ($tocf eq "") { $main .= "\n!TOC!\n"; $tocf = "toc"; }
  127.         if (defined $info{'LAYOUT'} and $info{'LAYOUT'} eq "slide")
  128.         {
  129.           $main .= "\n<<H$x$align><A NAME=\"AA$hcount\">$h1$htext$h2<\/A></H$x>\n\n";
  130.           $toc[$hcount-1] = "<A HREF=\"$qfile$hcount.html\">$htext<\/A>";
  131.         }
  132.         else
  133.         {
  134.           $main .= "\n<H$x$align><A NAME=\"AA$hcount\">$h1$htext$h2<\/A></H$x>\n\n";
  135.           $toc[$hcount-1] = "$x|<A HREF=\"#AA$hcount\">$htext<\/A>";
  136.         }
  137.       }
  138.     }
  139.     elsif (/^\|.*/)                      # table (|)
  140.     {
  141.       if (/^\|-.*/) { &flush_table; }
  142.       else
  143.       {
  144.         &flush_para;
  145.         if (!$caption) { $caption = "$&"; } else { $table[$tcount++] = "$&"; }
  146.       }
  147.     }
  148.     elsif (/(^\s+)(.*)/)                 # list (space or tab)
  149.     {
  150.       &flush_para;
  151.       if ($acount == 0)
  152.       {
  153.         $x = length($1);
  154.         $list[$lcount++] = "$x $2";
  155.       }
  156.       else { $atxt[$acount] .= "\n<P>$2"; }
  157.     }
  158.     elsif (/^\?(.*)/)                    # question (?)
  159.     {
  160.       &flush_quest;
  161.       &flush_para;
  162.       &flush_list;
  163.       &flush_table;
  164.       &flush_pref;
  165.       $qcount++;
  166.       $1 =~ /(\w*)\??(\w*)/;
  167.       $qkey = $1;
  168.       $qmod = $2;
  169.       $qkey =~ tr/a-z/A-Z/;
  170.       $qmod =~ tr/a-z/A-Z/;
  171.       if ($info{'LAYOUT'} =~ /feedback/i) { $qmod = ""; }
  172.       if ($info{'LAYOUT'} =~ /nofeedback/i) { $qmod = "NONE"; }
  173.       if ($info{'LAYOUT'} =~ /print/i) { $qmod = "NONE"; }
  174.       if ($info{'QUIZCGI'}) { $qmod = "QUIZ"; }
  175.  
  176.       if ($info{'FILE'}) { $rfile = "$info{'FILE'}.html"; }
  177.       else { $rfile = "$qfile.html"; }
  178.  
  179.       $qtxt .= "$dtdinfo\n<HTML>\n\n$mtxinfo\n\n<HEAD>\n<TITLE>Feedback for Question $qcount</TITLE></HEAD>\n<BODY>\n\n";
  180.       $qtxt .= "<A HREF=\"$rfile\">$info{'TITLE'}</A>\n";
  181.       $qtxt .= "<H1>Question $qcount Feedback</H1>\n";
  182.       $x = length($qkey);
  183.       if ($x == 1) { $temp = "Single Best Answer" } else { $temp = "Best $x Answers" }
  184.       $main .= "<P><STRONG><BIG>Question $qcount - $temp</BIG></STRONG>\n";
  185.     }
  186.     elsif (/^@(.*)/)                     # answer (@)
  187.     {
  188.       &flush_para;
  189.       $acount++;
  190.       $temp = "$letters[$acount])";
  191.       $atxt[$acount] = "$temp $1";
  192.       $x = length($qkey);
  193.       if ($acount == 1) { $main .= "<BLOCKQUOTE>\n"; }
  194.  
  195.       if ($qmod eq "QUIZ")
  196.       {
  197.         if ($x == 1)
  198.           { $main .= "<P><INPUT TYPE=radio NAME=q$qcount VALUE=a$acount>$1\n"; }
  199.         else
  200.           { $main .= "<P><INPUT TYPE=checkbox NAME=q$qcount VALUE=a$acount>$1\n"; }
  201.  
  202.         $y = index($qkey, $letters[$acount]);
  203.  
  204.         if ($y >= 0 && $akey =~ /q$qcount=/)
  205.           { chop($akey); $akey .= ":a$acount\n"; }
  206.         elsif ($y >= 0)
  207.           { $akey .= "q$qcount=a$acount\n"; }
  208.         elsif ($x > 1 && $akey =~ /q$qcount=/)
  209.           { chop($akey); $akey .= ":x\n"; }
  210.         elsif ($x > 1)
  211.           { $akey .= "q$qcount=x\n"; }
  212.       }
  213.       elsif ($qmod eq "")
  214.       {
  215.         $main .= "<P><A HREF=\"$qfile$qcount$letters[$acount].html\">$temp $1</A>\n";
  216.  
  217.         if (index($qkey, $letters[$acount]) < 0)
  218.         {
  219.           if ($x == 1) { $atxt[$acount] .= "<P><A HREF=\"$qfile$qcount$qkey.html\"><STRONG><BIG>Sorry...</BIG></STRONG></A>"; }
  220.           else { $atxt[$acount] .= "<P><STRONG><BIG>Sorry...</BIG></STRONG>"; }
  221.         }
  222.         else
  223.         {
  224.           if ($x == 1) { $atxt[$acount] .= "<P><STRONG><BIG>Correct!</BIG></STRONG>"; }
  225.           else { $atxt[$acount] .= "<P><STRONG><BIG>Correct, but there are more...</BIG></STRONG>"; }
  226.         }
  227.       }
  228.       else { $main .= "<P>$temp $1\n"; }
  229.     }
  230.     elsif (/^-.*/)                       # horizontal rule (-)
  231.     {
  232.       &flush_list;
  233.       &flush_table;
  234.       &flush_pref;
  235.       $para .= "\n<HR SIZE=1>\n";
  236.     }
  237.     elsif (/^''(.*)/)                    # pull quote ('')
  238.     {
  239.       &flush_para;
  240.       &flush_list;
  241.       &flush_table;
  242.       &flush_pref;
  243.       $main .= "<P><HR SIZE=1><CENTER><STRONG><BIG>$1</BIG></STRONG></CENTER><HR SIZE=1>\n";
  244.     }
  245.     elsif (/^=(.*)/)                     # preformatted text (=)
  246.     {
  247.       &flush_para;
  248.       &flush_list;
  249.       &flush_table;
  250.       $pref[$pcount++] = $1;
  251.     }
  252.     else                                 # other stuff
  253.     {
  254.       &flush_list;
  255.       &flush_table;
  256.       &flush_pref;
  257.       if($para eq "") { $para = $_; }
  258.       else { $para .= " $_"; }
  259.     }
  260.   }
  261.  
  262.   &flush_quest;                          # flush everything just to be sure
  263.   &flush_para;
  264.   &flush_list;
  265.   &flush_table;
  266.   &flush_pref;
  267.  
  268.   ### fix up page info
  269.  
  270.   if (!$info{'MTX'})
  271.   { print "WARNING: The format of this file is unknown!\n"; }
  272.   elsif ($info{'MTX'} < 1.5)
  273.   { print "WARNING: The format of this file ($info{'MTX'}) is not current!\n"; }
  274.  
  275.   if ($info{'FILE'}) { $_[1] =~ s/(.*:).*/$1$info{'FILE'}\.html/; }
  276.   else { $_[1] =~ /.*:(.*)\.html/; $info{'FILE'} = $1; }
  277.  
  278.   if (!$info{'TITLE'}) { $info{'TITLE'} = $info{'FILE'}; }
  279.  
  280.   if (!$info{'HEADING'}) { $info{'HEADING'} = $info{'TITLE'}; }
  281.  
  282.   if ($info{'HEADING'} =~ /(^!\w*$)/) { $info{'HEADING'} = "$1 $info{'TITLE'}"; }
  283.  
  284.   if (!$info{'AUTHOR'}) { $info{'AUTHOR'} = $info{'AUTHURL'}; }
  285.  
  286.   if (!$info{'CONTACT'}) { $info{'CONTACT'} = $info{'CONTURL'}; }
  287.  
  288.   if (!$info{'VERSION'}) { $info{'VERSION'} = $info{'VERSURL'}; }
  289.  
  290.   if ($info{'HOMEURL'} && !$info{'HOME'}) { $info{'HOME'} = "Home Page" }
  291.  
  292.   if ($info{'PARENTURL'} && !$info{'PARENT'}) { $info{'PARENT'} = "Parent Page" }
  293.  
  294.   if ($info{'INDEXURL'} && !$info{'INDEX'}) { $info{'INDEX'} = "Index Page" }
  295.  
  296.   if ($info{'PREVURL'} && !$info{'PREV'}) { $info{'PREV'} = "Previous Page" }
  297.  
  298.   if ($info{'NEXTURL'} && !$info{'NEXT'}) { $info{'NEXT'} = "Next Page" }
  299.  
  300.   if ($info{'LAYOUT'} eq "print")
  301.   { $info{'OUTLINE'} = "none"; $info{'COUNTER'} = "";
  302.     $info{'HOMEURL'} = ""; $info{'PARENTURL'} = ""; $info{'INDEXURL'} = ""; 
  303.     $info{'PREVURL'} = ""; $info{'NEXTURL'} = ""; }
  304.  
  305.   if ($info{'LAYOUT'} eq "slide") { $info{'OUTLINE'} = "slide"; }
  306.  
  307.   if ($info{'REFRESH'} && $info{'LAYOUT'} eq "slide")
  308.     { $info{'REFRESH'} =~ s/^(\d+)$/<META HTTP-EQUIV=\"refresh\" CONTENT=\"$1; URL=/; }
  309.   elsif ($info{'REFRESH'} =~ /(\d+)\s+(.+)/)
  310.     { $info{'REFRESH'} =~ s/(\d+)\s+(.+)/<META HTTP-EQUIV=\"refresh\" CONTENT=\"$1; URL=$2\">/; }
  311.   elsif ($info{'REFRESH'})
  312.     { $info{'REFRESH'} =~ s/^(\d+)$/<META HTTP-EQUIV=\"refresh\" CONTENT=\"$1\">/; }
  313.  
  314.   if ($info{'LOGO'} =~ /(^\$?)(.+)/) { $info{'HEADING'} = "$1!$2"; }
  315.  
  316.   if ($info{'QUIZCGI'}) { $info{'STAMP'} = time; $info{'STAMP'} =~ s/\d*(\d\d\d\d$)/$1/; }
  317.  
  318.   if ($info{'QUIZLIST'}) { $info{'QUIZLIST'} .= ".lst"; }
  319.  
  320.   if ($info{'QUIZTYPE'} && !$info{'LAYOUT'}) { $info{'LAYOUT'} = "results"; }
  321.  
  322.   if ($info{'ABSTRACT'})
  323.     { $info{'ABSTRACT'} = "<META NAME=\"description\" CONTENT=\"$info{'ABSTRACT'}\">"; }
  324.  
  325.   if ($info{'KEYWORDS'})
  326.     { $info{'KEYWORDS'} = "<META NAME=\"keywords\" CONTENT=\"$info{'KEYWORDS'}\">"; }
  327.  
  328.   ### process embedded tags
  329.  
  330.   $main = &process_tags($main);
  331.  
  332.   ### build navigation buttons
  333.  
  334.   if ($info{'HOMEURL'} eq 'none') { $navi .= "$info{'HOME'} | "; }
  335.   elsif ($info{'HOMEURL'}) { $navi .= "<A HREF=\"$info{'HOMEURL'}\">$info{'HOME'}</A> | "; }
  336.  
  337.   if ($info{'PARENTURL'} eq 'none') { $navi .= "$info{'PARENT'} | "; }
  338.   elsif ($info{'PARENTURL'}) { $navi .= "<A HREF=\"$info{'PARENTURL'}\">$info{'PARENT'}</A> | "; }
  339.  
  340.   if ($info{'INDEXURL'} eq 'none') { $navi .= "$info{'INDEX'} | "; }
  341.   elsif ($info{'INDEXURL'}) { $navi .= "<A HREF=\"$info{'INDEXURL'}\">$info{'INDEX'}</A> | "; }
  342.  
  343.   if ($info{'PREVURL'} eq 'none') { $navi .= "$info{'PREV'} | "; }
  344.   elsif ($info{'PREVURL'}) { $navi .= "<A HREF=\"$info{'PREVURL'}\">$info{'PREV'}</A> | "; }
  345.  
  346.   if ($info{'NEXTURL'} eq 'none') { $navi .= "$info{'NEXT'} | "; }
  347.   elsif ($info{'NEXTURL'}) { $navi .= "<A HREF=\"$info{'NEXTURL'}\">$info{'NEXT'}</A> | "; }
  348.  
  349.   if ($navi) { chop($navi); chop($navi); chop($navi); $navi .= "\n"; }
  350.  
  351.   ### build page header
  352.  
  353.   $head = "$dtdinfo\n<HTML>\n\n$mtxinfo\n\n<HEAD>\n";
  354.   if ($info{'REFRESH'} && $info{'LAYOUT'} ne "slide") { $head .= "$info{'REFRESH'}\n"; }
  355.  
  356.   if ($info{'ABSTRACT'}) { $head .= "$info{'ABSTRACT'}\n"; }
  357.   if ($info{'KEYWORDS'}) { $head .= "$info{'KEYWORDS'}\n"; }
  358.  
  359.   $head .= "<TITLE>$info{'TITLE'}</TITLE>\n</HEAD>\n\n";
  360.  
  361.   if ($info{'WATERMARK'}) { $head .= "<BODY BACKGROUND=\"$path$info{'WATERMARK'}.gif\">\n"; }
  362.   elsif ($info{'COLORS'}) { $head .= "<BODY $info{'COLORS'}>\n"; }
  363.   else { $head .= "<BODY>\n"; }
  364.  
  365.   if ($navi) { $head .= $navi . "<HR SIZE=1>\n"; }
  366.  
  367.   if ($info{'HEADING'} =~ /^\$(.*)/) { $info{'HEADING'} = $1; $align = " ALIGN=center"; }
  368.   else { $align = ""; }
  369.  
  370.   $info{'HEADING'} =~ s/^!(\w*) ?(.*)/<IMG SRC=\"$path$1.gif\" ALT=\"$2\">/i;
  371.  
  372.   if ($main =~ /!HEAD!/) { $main =~ s/!HEAD!/<H1$align>$info{'HEADING'}<\/H1>/; }
  373.   else { $head .= "<H1$align>$info{'HEADING'}</H1>\n"; }
  374.  
  375.   if ($info{'QUIZCGI'}) { $head .= "<FORM METHOD=post ACTION=\"$info{'QUIZCGI'}\">\n"; }
  376.  
  377.   ### build page footer
  378.  
  379.   if ($info{'QUIZCGI'})
  380.   {
  381.     $tail .= "\n<HR SIZE=1>\n";
  382.     if ($info{'QUIZLIST'})
  383.       { $tail .= "   ID Code: <INPUT SIZE=15 TYPE=password NAME=id>   \n"; }
  384.     $tail .= "<INPUT TYPE=submit VALUE=\"Submit Answers\"> <INPUT TYPE=reset VALUE=\"Reset Form\">\n";
  385.     $tail .= "<INPUT TYPE=hidden NAME=stamp VALUE=$info{'STAMP'}>\n";
  386.     $tail .= "<INPUT TYPE=hidden NAME=number VALUE=$qcount>\n";
  387.   }
  388.  
  389.   if ($info{'COUNTER'})
  390.   {
  391.     $info{'COUNTER'} =~ /(\w* \d*, \d*) +(.*)/;
  392.     $tail .= "\n<HR SIZE=1>\n<EM>You are visitor  <IMG SRC=\"$2\" ALIGN=ABSMIDDLE> since $1.</EM>\n";
  393.   }
  394.  
  395.   if ($info{'LAYOUT'} eq "cover")
  396.   {
  397.     $tail .= "\n<TT>";
  398.   }
  399.   else
  400.   {
  401.     $ts = ×tamp;
  402.     $tail .= "\n<HR SIZE=1>\n<TT>";
  403.  
  404.     if ($info{'CREATED'})
  405.     {
  406.       $tail .= "\n  <STRONG>Created:</STRONG> $info{'CREATED'}";
  407.       $tail .= "\n <STRONG>Modified:</STRONG> $ts";
  408.                 }
  409.     else { $tail .= "\n  <STRONG>Updated:</STRONG> $ts"; }
  410.  
  411.     if ($info{'EXPIRES'})
  412.     {
  413.       $tail .= "\n <STRONG>Expires:</STRONG> $info{'EXPIRES'}";
  414.                 }
  415.   }
  416.  
  417.   if ($info{'VERSURL'})
  418.   {
  419.     $tail .= "\n<BR>  <STRONG>Version:</STRONG> <A HREF=\"$info{'VERSURL'}\">$info{'VERSION'}</A>";
  420.   }
  421.   elsif ($info{'VERSION'})
  422.   {
  423.     $tail .= "\n<BR>  <STRONG>Version:</STRONG> $info{'VERSION'}";
  424.   }
  425.  
  426.   if ($info{'AUTHURL'})
  427.   {
  428.     if($info{'AUTHURL'} =~ /.+@.+/) { $info{'AUTHURL'} = "mailto:" . $info{'AUTHURL'}; }
  429.     $tail .= "\n<BR>   <STRONG>Author:</STRONG> <A HREF=\"$info{'AUTHURL'}\">$info{'AUTHOR'}</A>";
  430.   }
  431.   elsif ($info{'AUTHOR'})
  432.   {
  433.     $tail .= "\n<BR>   <STRONG>Author:</STRONG> $info{'AUTHOR'}";
  434.   }
  435.  
  436.   if ($info{'CONTURL'})
  437.   {
  438.     if($info{'CONTURL'} =~ /.+@.+/) { $info{'CONTURL'} = "mailto:" . $info{'CONTURL'}; }
  439.     $tail .= "\n<BR>  <STRONG>Contact:</STRONG> <A HREF=\"$info{'CONTURL'}\">$info{'CONTACT'}</A>";
  440.   }
  441.   elsif ($info{'CONTACT'})
  442.   {
  443.     $tail .= "\n<BR>  <STRONG>Contact:</STRONG> $info{'CONTACT'}";
  444.   }
  445.  
  446.   if ($info{'PATH'})
  447.   {
  448.     $tail .= "\n<BR> <STRONG>Location:</STRONG> <A HREF=\"$info{'PATH'}$info{'FILE'}.html\">$info{'PATH'}$info{'FILE'}.html</A>";
  449.   }
  450.  
  451.   if ($info{'COPYURL'})
  452.   {
  453.     $tail .= "\n<BR><STRONG>Copyright:</STRONG> <A HREF=\"$info{'COPYURL'}\">$info{'COPYRIGHT'}</A>";
  454.   }
  455.   elsif ($info{'COPYRIGHT'})
  456.   {
  457.     $tail .= "\n<BR><STRONG>Copyright:</STRONG> $info{'COPYRIGHT'}";
  458.   }
  459.  
  460.   if ($navi) { $tail .= "\n</TT>\n<HR SIZE=1>\n" . $navi; }
  461.   else { $tail .= "\n</TT>\n"; }
  462.  
  463.   if ($info{'QUIZCGI'}) { $tail .= "</FORM>\n"; }
  464.  
  465.   $tail .= "</BODY>\n</HTML>\n";
  466.  
  467.   ### build toc/outline
  468.  
  469.   $temp = "";
  470.  
  471.   if ($info{'OUTLINE'} eq "none" || $toc[0] eq "")
  472.   {
  473.     $toc = "<HR SIZE=1>";
  474.   }
  475.   elsif ($info{'OUTLINE'} eq "slide")
  476.   {
  477.     $toc = "<HR SIZE=1>\n<OL>\n";
  478.  
  479.     foreach $item (@toc) { $toc .= "<LI>$item\n"; }
  480.  
  481.     $toc .= "$temp</OL>\n<HR SIZE=1>\n\n";
  482.     $toc .= "<STRONG>A Note on These Slides: </STRONG>To begin, select any slide from ";
  483.     $toc .= "the list above. Use the controls (< i >) to move forward, backward, or return ";
  484.     $toc .= "to this index. Increase the font size of your browser for optimal viewing.";
  485.  
  486.     if ($x = index($main,"!TOC!"))
  487.     {
  488.       $stxt = substr($main,$x+6);
  489.       $main = substr($main,0,$x+6);
  490.     }
  491.   }
  492.   elsif ($info{'OUTLINE'} eq "long")
  493.   {
  494.     $level = 1;
  495.     foreach $item (@toc)
  496.     {
  497. #      print "$level $item\n";
  498.       $item =~ s/(.*)\|(.*)/<LI>$2/;
  499.       if ($1 == $level) { $temp .= "$item\n"; }
  500.       elsif ($1 > $level) { $temp .= "<UL>\n$item\n"; }
  501.       else
  502.       {
  503.         while($level > $1)
  504.         {
  505.           $level--;
  506.           $temp .= "</UL>\n";
  507.         }
  508.         $temp .= "$item\n";
  509.       }
  510.       $level = $1;
  511.     }
  512.  
  513.     while ($level > 1)
  514.     {
  515.        $level--;
  516.        $temp .= "</UL>\n";
  517.     }
  518.     $toc = "<HR SIZE=1>\n$temp<HR SIZE=1>";
  519.   }
  520.   else
  521.   {
  522.     foreach $item (@toc)
  523.     {
  524.       $item =~ s/(.*)\|(.*)/$2 \| /;
  525.       if ($1 == 2){ $temp .= "$item\n"; }
  526.     }
  527.     chop($temp); chop($temp); chop($temp);
  528.     $toc = "<HR SIZE=1>\n$temp\n<HR SIZE=1>";
  529.   }
  530.  
  531.   if ($main =~ /!TOC!/) { $main =~ s/!TOC!/$toc/; }
  532.  
  533.   ### output page
  534.  
  535.   open(OUTFILE,">$_[1]") || die "Can't open output file $_[1].\n";
  536.   print "writing: $_[1]\n";
  537.  
  538.   print OUTFILE "$head$main$tail";
  539.  
  540.   close(INFILE);
  541.   close(OUTFILE);
  542.  
  543.   MacPerl::SetFileInfo("MOSS", "TEXT", $_[1]);     # netscape creator (mac only)
  544.  
  545.   ### output slides
  546.  
  547.   $scount = 0;
  548.   $x = index($stxt,"<<H");
  549.   $stxt = substr($stxt,$x);
  550.   $stxt .= "<<H";
  551.  
  552.   while (($x = index($stxt,"<<H",1)) > -1)
  553.   {
  554.     $temp = substr($stxt,1,$x); $temp =~ s/<P>//; chop($temp);
  555.     $stxt = substr($stxt,$x);
  556.  
  557.     $scount++; $prevnum = $scount-1; $nextnum = $scount+1;
  558.     $file = "$qpath$qfile$scount.html";
  559.     $prev = "$qfile$prevnum.html";
  560.     $next = "$qfile$nextnum.html";
  561.     $refn = "$qfile$nextnum.html";
  562.     if ($scount == 1) { $prev = "$info{'FILE'}.html"; }
  563.     elsif ($scount == $hcount) { $next = "$info{'FILE'}.html"; $refn = $qfile . "1.html"; }
  564.  
  565. #    $picon = "prev.gif"; $iicon = "index.gif"; $nicon = "next.gif";
  566. #    $temp =~ s/.*<H.>(.*)<\/H.><\/A>/<TITLE>$info{'TITLE'} - $1<\/TITLE>\n<\/HEAD>\n<BODY>\n\n<A HREF=\"$prev\"><IMG SRC=\"$path$picon\" ALT=\"Prev\"><\/A><A HREF=\"$qfile.html\"><IMG SRC=\"$path$iicon\" ALT=\"Index\"><\/A><A HREF=\"$next\"><IMG SRC=\"$path$nicon\" ALT=\"Next\"><\/A><CENTER><STRONG>$1<\/STRONG><\/CENTER>\n<HR SIZE=1>\n/i;
  567.  
  568.     if ($info{'REFRESH'}) { $refresh = "$info{'REFRESH'}$refn\">"; }
  569.  
  570.     $controls = "<TT><A HREF=\"$prev\">< <\/A>";
  571.     $controls .= "<A HREF=\"$info{'FILE'}.html\">i<\/A>";
  572.     $controls .= "<A HREF=\"$next\"> ><\/A><\/TT>\n";
  573.     $body = "<BODY BGCOLOR=\"#0102FF\" TEXT=\"#FFFF04\" LINK=\"#00FF02\" ALINK=\"#FFFFFF\" VLINK=\"#00FF02\">";
  574.     $temp = "$dtdinfo\n<HTML>\n\n$mtxinfo\n\n<HEAD>\n$refresh\n" . $temp;
  575.     $temp =~ s/<H.><A.*>(.*)<\/A><\/H.>/<TITLE>$1 - $info{'TITLE'}<\/TITLE>\n<\/HEAD>\n$body\n\n$controls<CENTER><STRONG>$1<\/STRONG><\/CENTER>\n<HR SIZE=4>/i;
  576.     $temp .= "</BODY>\n</HTML>";
  577.  
  578.     open(OUTFILE,">$file") || die "Can't open output file $file.\n";
  579.     print "writing: $file\n";
  580.  
  581.     print OUTFILE $temp;
  582.     close(OUTFILE);
  583.   }
  584.  
  585.   ### output quiz key
  586.  
  587.   if ($info{'QUIZCGI'})
  588.   {
  589.     $file = "$qpath$qfile.key";
  590.     open(OUTFILE,">$file") || die "Can't open output file $file.\n";
  591.     print "writing: $file\n";
  592.  
  593.     print OUTFILE "$info{'TITLE'}\|$ts\|$info{'STAMP'}\|$info{'LAYOUT'}\|$info{'EXPIRES'}\|$info{'QUIZLIST'}\n$akey";
  594.     close(OUTFILE);
  595.   }
  596. }
  597.  
  598. ### add paragraph to main text ###
  599.  
  600. sub flush_para
  601. {
  602.   if ($para ne "")
  603.   {
  604.     if ($para =~ /^\$(.*)/) { $main .= "<P ALIGN=center>$1\n"; }
  605.     elsif ($para =~ /^\'(.*)/) { $main .= "<BLOCKQUOTE>$1</BLOCKQUOTE>\n"; }
  606.     elsif ($para =~ /^\+(.*)/ && $info{'LAYOUT'} ne "print") { $main .= "<P>$1\n"; }
  607.     elsif ($para =~ /^\+(.*)/ && $info{'LAYOUT'} eq "print") { ; } # do nothing
  608.     else { $main .= "<P>$para\n"; }
  609.  
  610.     if ($qtxt ne "") { $qtxt .= "<P>$para\n"; }
  611.  
  612.     $para = "";
  613.   }
  614. }
  615.  
  616. ### add preformatted text to main ###
  617.  
  618. sub flush_pref
  619. {
  620.   if (@pref)
  621.   {
  622.     $main .= "<PRE>";
  623.     foreach $item (@pref)
  624.     {
  625.       $main .= "$item\n";
  626.     }
  627.     $main .= "</PRE>\n";
  628.   }
  629.  
  630.   undef @pref;
  631.   $pcount = 0;
  632. }
  633.  
  634. ### add list to main text ###
  635.  
  636. sub flush_list
  637. {
  638.   $level = 0;
  639.  
  640.   foreach $item (@list)
  641.   {
  642.     $item =~ /(\d) (.)(.*)/;
  643.     $item = $3;
  644.  
  645.     if($2 eq "#") {$stag[$1] = "<OL>"; $etag[$1] = "</OL>"; $itag[$1] = "<LI>"; }
  646.     elsif($2 eq "@") {$stag[$1] = "<OL TYPE=a>"; $etag[$1] = "</OL>"; $itag[$1] = "<LI>"; }
  647.     elsif($2 eq "!") {$stag[$1] = "<OL TYPE=I>"; $etag[$1] = "</OL>"; $itag[$1] = "<LI>"; }
  648.     elsif($2 eq "+") {$stag[$1] = "<DL>"; $etag[$1] = "</DL>"; $itag[$1] = "<DT>"; $item = "<EM>$item</EM>"; }
  649.     elsif($2 eq "-") {$stag[$1] = "<DL>"; $etag[$1] = "</DL>"; $itag[$1] = "<DD>"; }
  650.     else {$stag[$1] = "<UL>"; $etag[$1] = "</UL>"; $itag[$1] = "<LI>"; $item = $2 . $3; }
  651.  
  652.     if ($1 > $level)                  # start list
  653.     {
  654.       $level = $1;
  655.       $main .= "$stag[$1]\n";
  656.     }
  657.     elsif ($1 < $level)               # end list
  658.     {
  659.       while ($1 < $level) { $main .= "$etag[$level--]\n"; }
  660.     }
  661.  
  662.     $main .= "$itag[$1]$item\n";      # list item
  663.   }
  664.   
  665.   while ($level > 0) { $main .= "$etag[$level--]\n"; }
  666.  
  667.   undef @list;
  668.   $lcount = 0;
  669. }
  670.  
  671. ### add table to main text ###
  672.  
  673. sub flush_table
  674. {
  675.   if (@table)
  676.   {
  677.     $caption =~ s/^\|([^|]*)(.*)/$1/;
  678.     $type = $2;
  679.     $caption =~ s/none//i;
  680.  
  681.     if ($type =~ /(nowide\|noborder|noborder\|nowide)/)
  682.     { $main .= "<CENTER><P><TABLE>\n"; }
  683.     elsif ($type =~ /nowide/)
  684.     { $main .= "<CENTER><P><TABLE BORDER=6 CELLPADDING=2 CELLSPACING=1>\n"; }
  685.     elsif ($type =~ /noborder/)
  686.     { $main .= "<CENTER><P><TABLE WIDTH=\"95%\">\n"; }
  687.     else
  688.     { $main .= "<CENTER><P><TABLE BORDER=6 CELLPADDING=2 CELLSPACING=1 WIDTH=\"95%\">\n"; }
  689.  
  690.     if ($caption)
  691.     { $main .= "<CAPTION><STRONG><EM>" . $caption . "</EM></STRONG></CAPTION>\n"; }
  692.  
  693.     foreach $item (@table)
  694.     {
  695.       $main .= "<TR>";
  696.  
  697.       while ($item)
  698.       {
  699.         $item =~ s/^\|([^|]*)(.*)/$2/;
  700.         $cell = $1;
  701.  
  702.         $cell =~ s/(.*[\S|\*])(\s*$)/$1/;
  703.         $cell =~ s/(^[\*|^]?)(.*)/$2/;
  704.         $tag = $1;
  705.         $cell =~ s/\s*//;
  706.  
  707.         if ($cell =~ /(.*)\\(\d*)/) { $cell = $1; $col = " COLSPAN=$2 ALIGN=center>"; }
  708.         else { $col = ">"; }
  709.  
  710.         if ((!$cell) && ($type =~ /noblanks/)) { $tag = "*"; }
  711.  
  712.         if (($tag eq "*") && $cell) { $main .= "<TH" . $col . $cell . "</TH>"; }
  713.         elsif ($tag eq "*") { $main .= "<TD>" . " " . "</TD>"; }
  714.         elsif ($tag eq "^") { $main .= "<TD VALIGN=top" . $col . $cell . "</TD>"; }
  715.         else { $main .= "<TD" . $col . $cell . "</TD>"; }
  716.       }
  717.       $main .= "</TR>\n";
  718.     }
  719.   $main .= "</TABLE></CENTER>\n";
  720.   }
  721.  
  722.   undef @table;
  723.   undef $caption;
  724.   $tcount = 0;
  725. }
  726.  
  727. ### output question feedback files ###
  728.  
  729. sub flush_quest
  730. {
  731.   if ($acount > 0)
  732.   {
  733.     $main .= "</BLOCKQUOTE>\n"; # ??dead code??
  734.  
  735.     if ($qmod eq "")
  736.     {
  737.       $cnt = 0;
  738.       $qtxt = &process_tags($qtxt);
  739.  
  740.       while ($acount > $cnt)
  741.       {
  742.         $cnt++;
  743.  
  744.         $file = "$qpath$qfile$qcount$letters[$cnt].html";
  745.  
  746.         open(OUTFILE,">$file") || die "Can't open output file $file.\n";
  747.         print "writing: $file\n";
  748.  
  749.         $atxt[$cnt] = &process_tags($atxt[$cnt]);
  750.  
  751.         print OUTFILE "$qtxt\n<BLOCKQUOTE>\n<P>";
  752.         print OUTFILE "$atxt[$cnt]\n";
  753.         print OUTFILE "</BLOCKQUOTE>\n</BODY>\n</HTML>";
  754.  
  755.         close(OUTFILE);
  756.                   }
  757.     }
  758.  
  759.     undef $qtxt;
  760.     undef $qkey;
  761.     undef $qmod;
  762.     undef @atxt;
  763.     $acount = 0;
  764.   }
  765. }
  766.  
  767. ### process embedded tags ###
  768.  
  769. sub process_tags
  770. {
  771.   $temp = $_[0];
  772.  
  773.   $temp =~ s/{P}/<P>/gi;
  774.   $temp =~ s/{B}/<BR>/gi;
  775.   $temp =~ s/{S}/ /gi;
  776.   $temp =~ s/{C}/<BR CLEAR=all>/gi;
  777.  
  778.   $temp =~ s/{!/<EM>/g; $temp =~ s/!}/<\/EM>/g;
  779.   $temp =~ s/{\*/<STRONG>/g; $temp =~ s/\*}/<\/STRONG>/g;
  780.   $temp =~ s/{@/<TT>/g; $temp =~ s/@}/<\/TT>/g;            # F replaces @
  781.  
  782.   $temp =~ s/{F/<TT>/g; $temp =~ s/F}/<\/TT>/g;
  783.   $temp =~ s/{B/<BIG>/g; $temp =~ s/B}/<\/BIG>/g;
  784.   $temp =~ s/{S/<SMALL>/g; $temp =~ s/S}/<\/SMALL>/g;
  785.   $temp =~ s/{P/<SUP>/g; $temp =~ s/P}/<\/SUP>/g;
  786.   $temp =~ s/{N/<SUB>/g; $temp =~ s/N}/<\/SUB>/g;
  787.  
  788.   $temp =~ s/{#([^{}]*@[^{}]*)##}/<A HREF=\"mailto:$1\">$1<\/A>/g;
  789.   $temp =~ s/{#([^{}]*)##}/<A HREF=\"$1\">$1<\/A>/g;
  790.   $temp =~ s/{#([^{}]*)#=([^{}]*)#}/<A NAME=\"$2\">$1<\/A>/g;
  791.   $temp =~ s/{#([^{}]*)#(#[^{}]*)#}/<A HREF=\"$2\">$1<\/A>/g;
  792.   $temp =~ s/{#([^{}#]*)#([^{}]*@[^{}]*)#}/<A HREF=\"mailto:$2\">$1<\/A>/g;
  793.   $temp =~ s/{#([^{}#]*)#([^{}]*)#}/<A HREF=\"$2\">$1<\/A>/g;
  794.  
  795.   $temp =~ s/{=(\w*)=}/<IMG SRC=\"$path$1.gif\">/gi;
  796.   $temp =~ s/{=(\w*) (.*)=}/<IMG SRC=\"$path$1.gif\" ALT=\"$2\">/gi;
  797.   $temp =~ s/{=\$(\w*)=}/<IMG SRC=\"$path$1.gif\" ALIGN=absmiddle>/gi;
  798.   $temp =~ s/{=\$(\w*) (.*)=}/<IMG SRC=\"$path$1.gif\" ALIGN=absmiddle ALT=\"$2\">/gi;
  799.   $temp =~ s/{=\\(\w*)=}/<IMG SRC=\"$path$1.gif\" ALIGN=left>/gi;
  800.   $temp =~ s/{=\\(\w*) (.*)=}/<IMG SRC=\"$path$1.gif\" ALIGN=left ALT=\"$2\">/gi;
  801.   $temp =~ s/{=\/(\w*)=}/<IMG SRC=\"$path$1.gif\" ALIGN=right>/gi;
  802.   $temp =~ s/{=\/(\w*) (.*)=}/<IMG SRC=\"$path$1.gif\" ALIGN=right ALT=\"$2\">/gi;
  803.  
  804.   $temp =~ s/{\+(\w*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\"><\/A>/gi;
  805.   $temp =~ s/{\+(\w*) (.*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\" ALT=\"$2\"><\/A>/gi;
  806.   $temp =~ s/{\+\$(\w*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\" ALIGN=absmiddle><\/A>/gi;
  807.   $temp =~ s/{\+\$(\w*) (.*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\" ALIGN=absmiddle ALT=\"$2\"><\/A>/gi;
  808.   $temp =~ s/{\+\\(\w*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\" ALIGN=left><\/A>/gi;
  809.   $temp =~ s/{\+\\(\w*) (.*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\" ALIGN=left ALT=\"$2\"><\/A>/gi;
  810.   $temp =~ s/{\+\/(\w*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\" ALIGN=right><\/A>/gi;
  811.   $temp =~ s/{\+\/(\w*) (.*)\+}/<A HREF=\"$path$1.jpg\"><IMG SRC=\"$path$1.gif\" ALIGN=right ALT=\"$2\"><\/A>/gi;
  812.  
  813.   $temp =~ s/{-(\w*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\"><\/A>/gi;
  814.   $temp =~ s/{-(\w*) (.*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\" ALT=\"$2\"><\/A>/gi;
  815.   $temp =~ s/{-\$(\w*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\" ALIGN=absmiddle><\/A>/gi;
  816.   $temp =~ s/{-\$(\w*) (.*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\" ALIGN=absmiddle ALT=\"$2\"><\/A>/gi;
  817.   $temp =~ s/{-\\(\w*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\" ALIGN=left><\/A>/gi;
  818.   $temp =~ s/{-\\(\w*) (.*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\" ALIGN=left ALT=\"$2\"><\/A>/gi;
  819.   $temp =~ s/{-\/(\w*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\" ALIGN=right><\/A>/gi;
  820.   $temp =~ s/{-\/(\w*) (.*)-}/<A HREF=\"$path$1L.gif\"><IMG SRC=\"$path$1.gif\" ALIGN=right ALT=\"$2\"><\/A>/gi;
  821.  
  822.   $temp =~ s/{#(\w*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\"><\/A>/gi;
  823.   $temp =~ s/{#(\w*) (.*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\" ALT=\"$2\"><\/A>/gi;
  824.   $temp =~ s/{#\$(\w*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\" ALIGN=absmiddle><\/A>/gi;
  825.   $temp =~ s/{#\$(\w*) (.*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\" ALIGN=absmiddle ALT=\"$2\"><\/A>/gi;
  826.   $temp =~ s/{#\\(\w*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\" ALIGN=left><\/A>/gi;
  827.   $temp =~ s/{#\\(\w*) (.*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\" ALIGN=left ALT=\"$2\"><\/A>/gi;
  828.   $temp =~ s/{#\/(\w*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\" ALIGN=right><\/A>/gi;
  829.   $temp =~ s/{#\/(\w*) (.*)#}/<A HREF=\"$1.html\"><IMG SRC=\"$path$1.gif\" ALIGN=right ALT=\"$2\"><\/A>/gi;
  830.  
  831.   $temp =~ s/{M(\w*)M}/<EMBED SRC=\"$path$1.mov\" $movinfo>/g;
  832.   $temp =~ s/{M\\(\w*)M}/<EMBED SRC=\"$path$1.mov\" ALIGN=left $movinfo>/g;
  833.   $temp =~ s/{M\/(\w*)M}/<EMBED SRC=\"$path$1.mov\" ALIGN=right $movinfo>/g;
  834.   $temp =~ s/{M\$(\w*)M}/<EMBED SRC=\"$path$1.mov\" ALIGN=absmiddle $movinfo>/g;
  835.   $temp =~ s/{M\!(\w*)M}/<EMBED SRC=\"$path$1.mov\" HIDDEN $movinfo>/g;
  836.  
  837.     $align =~ /\!/ and $align = " HIDDEN=\"true\"";
  838.  
  839.  
  840.   if (($x = index($temp,"{")) > -1 || ($x = index($temp,"}")) > -1)
  841.   {
  842.     $part = substr($temp,$x-3,12);
  843.     print "WARNING: This file contains unrecognized tags! ...$part...\n";
  844.   }
  845.  
  846.   $temp =~ s/≤/{/gi;                       # for { and } in output
  847.   $temp =~ s/≥/}/gi;
  848.  
  849.   return $temp;
  850. }
  851.  
  852. ### time stamp routine ###
  853.  
  854. sub timestamp
  855. {
  856.   @months = ("January","February","March","April","May","June",
  857.   "July","August","September","October","November","December",);
  858.  
  859.   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  860.  
  861. #  if ($hour < 10) { $zero = "0"; } else { $zero = ""; }
  862. #  return "$months[$mon] $mday, 19$year at $zero$hour$min";
  863.  
  864.   if ($hour > 11) { $mm = "PM"; } else { $mm = "AM"; }
  865.  
  866.   if ($hour > 12) { $hour -= 12; }
  867.  
  868.   if ($hour < 1) { $hour = 12; }
  869.  
  870.   if ($min < 10) { $min = "0" . $min; }
  871.  
  872.   return "$months[$mon] $mday, 19$year";
  873.  
  874. #  return "$months[$mon] $mday, 19$year at $hour:$min $mm";
  875. }
  876.